package com.tuanzi.loan.web.bean.settlementsystem;

import com.google.common.collect.Lists;
import com.tuanzi.loan.business.service.settlementsystem.SettlementProductService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.vo.request.settlementsystem.SettlementProductRequest;
import com.tuanzi.loan.vo.response.settlementsystem.SettlementProductResponse;
import com.tuanzi.loan.web.configuration.JSFListingSessionBean;
import com.tuanzi.loan.web.lazy.settlementsystem.SettlementProductLazyDataModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.faces.bean.ViewScoped;
import java.util.List;

import static com.tuanzi.loan.business.constants.DictionaryCode.*;

/**
 * @author caiwanlin
 * @create 2018-08-16 20:30
 */
@Data
@Debug
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class SettlementProductListBean extends JSFListingSessionBean<SettlementProductRequest,SettlementProductResponse> {

    @Autowired
    private SettlementProductService settlementProductService;

    @Override
    protected String page() {
        return "/views/settlementsystem/product-list.xhtml";
    }

    @Override
    protected void initLazyDataModel() {
        $ = new SettlementProductRequest();
        lazyDataModel = new SettlementProductLazyDataModel($, session, settlementProductService);
    }

    public void onReset() throws Exception{
        initLazyDataModel();
    }

    public String onAdd(){
        return redirect("/views/settlementsystem/product-info.xhtml");
    }

    public String onSee(Long id){
        return redirect("/views/settlementsystem/product-info.xhtml?id="+id);
    }

    @Override
    protected List<String> getDictionaryCodes() {
        return  Lists.newArrayList(SETTLEMENT_INCOME_TYPE, COOPERATION_MODE, SETTLEMENT_CYCLE);
    }
}
